package com.ely.coupon.common.core.result;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private String msg;
    private int  code;
    private T  data;

    private ResponseResult(String msg, int code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }
    public  static  <T> ResponseResult<T> success(T data) {
        return  success(ResponseCode.SUCCESS,data);
    }

    public  static  <T> ResponseResult<T> success(ResponseCode responseCode,T data) {
        return common(responseCode,data);
    }

    public  static  <T> ResponseResult<T> error() {
        return  error(ResponseCode.SYS_ERROR,null);
    }

    public  static  <T> ResponseResult<T> error(ResponseCode responseCode) {
        return  error(responseCode,null);
    }

    public  static  <T> ResponseResult<T> error(ResponseCode responseCode,T data) {
        return  common(responseCode,data);
    }

    private   static  <T> ResponseResult<T> common(ResponseCode responseCode,T data) {
     return  new ResponseResult<T>(responseCode.getMsg(),responseCode.getCode(),data);
    }

}
